
export default {
    // 购物车件数
  	totalCount: (state) => {
      return state.cartList.reduce((total, item) => total + item.num, 0);
    },
    // 购物车总金额
    totalAmount: (state) => {
      return state.cartList.reduce((total, item) => total + item.num * item.salePrice, 0);
    },
    // 会员价总金额
    totalVipAmount: (state) => {
      return state.cartList.reduce((total, item) => total + item.num * item.vipPrice, 0);
    },
    // 待付金额
    unpaid: (state) => {
      console.log(state.totalOrderAmt,state.giveChange,state.payAmt,state.discountAmt,state.vipDiscount);
      if((Number(state.totalOrderAmt) + Number(state.giveChange) - Number(state.payAmt)  - Number(state.discountAmt) - Number(state.vipDiscount))>= 0){
        return Number(state.totalOrderAmt) + Number(state.giveChange) - Number(state.payAmt)  - Number(state.discountAmt) - Number(state.vipDiscount)
      }else{
        return 0
      }
      
      // return state.totalOrderAmt - state.payAmt + state.giveChange  - state.discountAmt
    },
    // 已付金额
    totalAmt: (state) => {
      return state.payAmt - state.giveChange
    },
    // 是否失效
    expire: (state) => {
      if (state.payInfo.countKey < 1) {
        return true
      } else {
        return false
      }
    },
    // 倒计时文字
    countValue: (state) => {
      const seconds = state.payInfo.countKey
      if (seconds < 1) {
        return '收款码已失效';
      }
      const minutes = Math.floor(seconds / 60);
      const remainingSeconds = seconds % 60;
      const formattedMinutes = String(minutes).padStart(2, '0');
      const formattedSeconds = String(remainingSeconds).padStart(2, '0');
      return `${formattedMinutes}:${formattedSeconds}`;
    },
}